package com.david.zhufengfm.adapters;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import com.david.zhufengfm.Fragments.BaseFragment;

import java.util.List;

/**
 * Created by David on 2015/10/20.
 * qq:978944820
 */
public class CommonFragmentAdapter extends FragmentPagerAdapter{
    private List<BaseFragment>fragments;

    /**
     *
     * @param fm
     * @param fragments
     */
    public CommonFragmentAdapter(FragmentManager fm, List<BaseFragment>fragments) {
        super(fm);
        this.fragments=fragments;
    }

    @Override
    public Fragment getItem(int position) {
        return fragments.get(position);
    }

    @Override
    public int getCount() {
        int count=0;
        if (fragments != null) {
            count=fragments.size();
        }
        return count;
    }

    @Override
    public CharSequence getPageTitle(int position) {
        String title=null;
        if (fragments != null) {
            BaseFragment baseFragment = fragments.get(position);
            title = baseFragment.getFragmentTitle();
        }
        return title;
    }
}
